#!/bin/bash
#2020年7月13日20:37:02
#auto congfig nginx virtual hosts
#by author www.jfedu.net
########################
#Install nginx web
yum install -y wget gzip tar make gcc
yum install -y pcre pcre-devel zlib-devel
wget -c http://nginx.org/download/nginx-1.16.0.tar.gz
ls -l nginx-1.16.0.tar.gz
tar -xzvf nginx-1.16.0.tar.gz
cd nginx-1.16.0/
useradd -s /sbin/nologin www -M
./configure --prefix=/usr/local/nginx/ --user=www --group=www --with-http_stub_status_module
make
make install
/usr/local/nginx/sbin/nginx
ps -ef|grep nginx
netstat -tnlp|grep 80
setenforce 0
systemctl stop firewalld.service

#Config nginx virtual hosts
cd /usr/local/nginx/conf/
\cp nginx.conf nginx.conf.bak
cat>nginx.conf<<EOF
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    include domains/*;
}
EOF
mkdir -p domains
cd domains/
cat>v1.jfedu.net <<EOF
server {
        listen       80;
        server_name  v1.jfedu.net;
        location / {
            root   html/v1.jfedu.net;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}
EOF
mkdir -p /usr/local/nginx/html/v1.jfedu.net/
cd /usr/local/nginx/html/v1.jfedu.net/
cat>index.html<<EOF
<html>
<h1>v1.jfedu.net Test Pages</h1>
<hr color=red>
</html>
EOF
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
